package hu.lacimol.tutorial.todo.action;

import hu.lacimol.tutorial.todo.model.Todo;
import hu.lacimol.tutorial.todo.service.TodoService;

import java.util.Date;

public class AddTodoAction extends TodoAction {

	private static final long serialVersionUID = -2345865120367035004L;

	public AddTodoAction(TodoService todoService) {
		super(todoService);
	}

	@Override
	public String doExecute() throws Exception {
		final String description = request.getParameter("description");
		Todo todo = this.todoService.create(description);
		this.todoService.addComment(todo, "Created at " + new Date());

		return getRedirect(VIEW_PAGE);
	}

	@Override
	public void doValidation() {
		doFieldValidation();
	}

	public String doAdd() throws Exception {
		return INPUT;
	}

}